﻿function Ajax()
{
  this.xml=false;

this.GetXmlHttp=function()
{
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try {
	  this.xml = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
		this.xml = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) {
		this.xml = false;
	  }
	}
	@end @*/

	if (!this.xml && typeof XMLHttpRequest != 'undefined') {
	  this.xml = new XMLHttpRequest();
	}
}
	this.GetXmlHttp();
	var xmlHttp = this.xml;
	var ajax=this;
	
	var callBack=null;

	this.updatePage=function() {

  if (xmlHttp.readyState == 4) {

        
        var response = eval('('+xmlHttp.responseText+')');
	
	    if(callBack!=null && typeof  callBack == "function")
	    {
	        callBack(response);
	    }
  }
}

this.toQueryString=function(json)
{
        var query="";
        if(json!=null)
        { 
                for(var param in json)
                {
                    query+=param+"="+escape(json[param])+"&"
                }
          }
        
       return query; 
}

this.invoke=function(opName,params,pageCallBack,method)
{
    var _flag = false;
    var domainUrl = "";
    
   
    if(xmlHttp)
    {

          var query="";
            query+=this.toQueryString(params);
            query=query.substring(0,query.length-1);
           callBack= pageCallBack;
            
            if(method!=null &&method.toUpperCase()=="GET")
            {
                     var url = "/ajaxUtil.aspx?opName="+opName+"&"+query;
                     if(_flag)
                     {
                        url = domainUrl + url;
                     }
                    xmlHttp.onreadystatechange = ajax.updatePage;
                    xmlHttp.open("GET", url, true);
                     xmlHttp.setRequestHeader("TIYMAAJAX-Ver","ver1.0");
                    xmlHttp.send(null);
              }else{
             
                    
                           url= "/ajaxUtil.aspx?opName="+opName; 
                   
                    
                    if(_flag)
                     {
                        url = domainUrl + url;
                     }
                    
                 
                     xmlHttp.onreadystatechange =ajax.updatePage; 
			
                    xmlHttp.open("POST", url, true);
                     xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
                     xmlHttp.setRequestHeader("TIYMAAJAX-Ver","ver1.0");
                    xmlHttp.send(query);
             } 
        }
    }
}


var MyAjax={
	GetDataList:function(pageIndex,pageSize,totalCount, procName,strWhere)
	{
	    new Ajax().invoke("GetDataList",{"pageIndex":pageIndex,"pageSize":pageSize,"procName":procName,"totalCount":totalCount, "strWhere":strWhere},arguments[5]);
	},
	ExcuteScript:function(procName,script)
	{
	    new Ajax().invoke("ExcuteScript",{"procName":procName, "script":script},arguments[2]);
	}
}


function $(objName)
{
   if(document.getElementById)
   {
        return document.getElementById(objName)
   }
   else
   {
        if(document.layers)
        {
            return eval("document.layers['"+objName+"']")
        }
        else
        {
            return eval("document.all."+objName)
        }
   }
}